$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../ext"))
require "test/unit"
require "alglib"
require 'matrix'
class TestAlglibPca < Test::Unit::TestCase
  def test_pca
    a=[10,20,30,40,50,60,70,80,90,100]
    b=[1.2,2.3,3.4,4,5,6,7,8,9,10]
    c=[6,8,3,6,8,2,3,9,10,1]
    d=[61,82,31,62,86,21,33,99,101,12]
    matrix=Matrix.columns([a,b,c,d])
    input_2d_array=matrix.to_alglib_matrix
    npoints=a.size
    nvars=4
    info=1
    s2=Alglib_ext::Real1dArray.new
    v=Alglib_ext::Real2dArray.new
    a=Alglib_ext.pcabuildbasis(input_2d_array,npoints,nvars, s2,v)
    comp=s2.to_a
    sum=comp.inject{|a,val| a+val}
    
    new=comp.collect{|val| (4.0*val).quo(sum)}
    p new
    p v.to_2d_a
  end
end
